'use strict';
const BaseController = require('../base');
const {
  addCommentValidate,
  commentListValidate,
} = require('@validators/comments');

class CommentsController extends BaseController {
  async add() {
    const { ctx } = this;
    const v = await addCommentValidate(ctx);
    await ctx.service.comments.add({
      userId: ctx.userId,
      houseId: v.get('path.houseId'),
      msg: v.get('body.comment'),
      createTime: ctx.helper.nowTime(),
    });

    ctx.helper.success();
  }

  async lists() {
    const { ctx } = this;
    const v = await commentListValidate(ctx);
    const result = await ctx.service.comments.lists({
      houseId: v.get('path.houseId'),
      ...ctx.params(),
    });

    this.success(result);
  }
}

module.exports = CommentsController;
